package cn.edu.lingnan.servlet;

import cn.edu.lingnan.pojo.User;
import cn.edu.lingnan.service.userservice;
import cn.edu.lingnan.service.userserviceimp;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/delete")
public class DeleteServlet extends HttpServlet {
    userservice us=new userserviceimp();
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String[] ids =  req.getParameterValues("ids");
        Integer[] idsInt = new Integer[ids.length];
        for (int i = 0; i < ids.length; i++) {
            idsInt[i] = Integer.parseInt(ids[i]);
        }
        System.out.println(idsInt[0]);
        us.deleteUser(idsInt);
        List<User> userList = us.selectall();
        req.getServletContext().setAttribute("userList", userList);

        req.getRequestDispatcher("/manager/student.jsp").forward(req,resp);
    }

}